This program to extract the text from an HTML address tag using Python.
CODE:
import requests from bs4 import BeautifulSoup url = 'https://www.justdial.com/Pune/Amrit-Guest-House-Behind-Hoshtel99-Koregaon-Park/020PXX20-XX20-240110203615-G5H8_BZDET?ncatid=10255012&area=&search=Top%20Amrit%20Guest%20House%20Behind%20Hoshtel99%20Koregaon%20Park%20in%20Pune&mncatname=Amrit%20Guest%20House%20Behind%20Hoshtel99%20Koregaon%20Park&search_id=a0b376a253daae9a9afb91e2da4229f66d238683c1e07ff9daf9f023b4fef7e8&abd_btn=&abd_heading=&isFreetxt=1&bd=2' # Replace with the actual URL response = requests.get(url) soup = BeautifulSoup(response.content, 'html.parser') address_tag = soup.find('address') address_text = address_tag.get_text(strip=True) print("Text from <address> tag:")print(address_text)
I got this following error while running the above code.
Solution:
import requests from bs4 import BeautifulSoup url = 'https://www.justdial.com/Pune/Amrit-Guest-House-Behind-Hoshtel99-Koregaon-Park/020PXX20-XX20-240110203615-G5H8_BZDET?ncatid=10255012&area=&search=Top%20Amrit%20Guest%20House%20Behind%20Hoshtel99%20Koregaon%20Park%20in%20Pune&mncatname=Amrit%20Guest%20House%20Behind%20Hoshtel99%20Koregaon%20Park&search_id=a0b376a253daae9a9afb91e2da4229f66d238683c1e07ff9daf9f023b4fef7e8&abd_btn=&abd_heading=&isFreetxt=1&bd=2' # Replace with the actual URL headers = { "User-Agent" : "My Agent" } response = requests.get(url, headers= headers) soup = BeautifulSoup(response.content, 'html.parser') address_tag = soup.find('address') address_text = address_tag.get_text(strip=True) print("Text from <address> tag:") print(address_text)
VIDEO GUIDE:
Post your comments / questions
Recent Article
- How to create custom 404 error page in Django?
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
Related Article